{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "impressed-accessory",
   "metadata": {},
   "source": [
    "## Seldon V2 Multi-Namespace Kubernetes Example\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "e09cb983",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Release \"seldon-core-v2-crds\" does not exist. Installing it now.\n",
      "NAME: seldon-core-v2-crds\n",
      "LAST DEPLOYED: Tue Aug 15 11:01:03 2023\n",
      "NAMESPACE: seldon-mesh\n",
      "STATUS: deployed\n",
      "REVISION: 1\n",
      "TEST SUITE: None\n"
     ]
    }
   ],
   "source": [
    "!helm upgrade --install seldon-core-v2-crds  ../k8s/helm-charts/seldon-core-v2-crds -n seldon-mesh"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "448aed9c",
   "metadata": {},
   "source": [
    " The below setup also illustrates using kafka specific prefixes for topics and consumerIds for isolation where the kafka cluster is shared with other applications and you want to enforce constraints. You would not strictly need this in this example as we install Kafka just for Seldon here."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "a4debc76",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Release \"seldon-v2\" does not exist. Installing it now.\n",
      "NAME: seldon-v2\n",
      "LAST DEPLOYED: Tue Aug 15 11:01:07 2023\n",
      "NAMESPACE: seldon-mesh\n",
      "STATUS: deployed\n",
      "REVISION: 1\n",
      "TEST SUITE: None\n"
     ]
    }
   ],
   "source": [
    "!helm upgrade --install seldon-v2 ../k8s/helm-charts/seldon-core-v2-setup/ -n seldon-mesh \\\n",
    "    --set controller.clusterwide=true \\\n",
    "    --set kafka.topicPrefix=myorg \\\n",
    "    --set kafka.consumerGroupIdPrefix=myorg"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "29353104",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "namespace/ns1 created\n",
      "namespace/ns2 created\n"
     ]
    }
   ],
   "source": [
    "!kubectl create namespace ns1\n",
    "!kubectl create namespace ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "id": "56cdf114",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NAME: seldon-v2-runtime\r\n",
      "LAST DEPLOYED: Tue Aug 15 11:01:11 2023\r\n",
      "NAMESPACE: ns1\r\n",
      "STATUS: deployed\r\n",
      "REVISION: 1\r\n",
      "TEST SUITE: None\r\n"
     ]
    }
   ],
   "source": [
    "!helm install seldon-v2-runtime ../k8s/helm-charts/seldon-core-v2-runtime  -n ns1 --wait"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "4b815db6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NAME: seldon-v2-servers\r\n",
      "LAST DEPLOYED: Tue Aug 15 10:47:31 2023\r\n",
      "NAMESPACE: ns1\r\n",
      "STATUS: deployed\r\n",
      "REVISION: 1\r\n",
      "TEST SUITE: None\r\n"
     ]
    }
   ],
   "source": [
    "!helm install seldon-v2-servers ../k8s/helm-charts/seldon-core-v2-servers  -n ns1 --wait"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "3ce2d189",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NAME: seldon-v2-runtime\r\n",
      "LAST DEPLOYED: Tue Aug 15 10:53:12 2023\r\n",
      "NAMESPACE: ns2\r\n",
      "STATUS: deployed\r\n",
      "REVISION: 1\r\n",
      "TEST SUITE: None\r\n"
     ]
    }
   ],
   "source": [
    "!helm install seldon-v2-runtime ../k8s/helm-charts/seldon-core-v2-runtime  -n ns2 --wait"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "4a214689",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "NAME: seldon-v2-servers\r\n",
      "LAST DEPLOYED: Tue Aug 15 10:53:28 2023\r\n",
      "NAMESPACE: ns2\r\n",
      "STATUS: deployed\r\n",
      "REVISION: 1\r\n",
      "TEST SUITE: None\r\n"
     ]
    }
   ],
   "source": [
    "!helm install seldon-v2-servers ../k8s/helm-charts/seldon-core-v2-servers  -n ns2 --wait"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "b194c88e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "server.mlops.seldon.io/mlserver condition met\n",
      "server.mlops.seldon.io/triton condition met\n"
     ]
    }
   ],
   "source": [
    "!kubectl wait --for condition=ready --timeout=300s server --all -n ns1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "60016845",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "server.mlops.seldon.io/mlserver condition met\n",
      "server.mlops.seldon.io/triton condition met\n"
     ]
    }
   ],
   "source": [
    "!kubectl wait --for condition=ready --timeout=300s server --all -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "sunrise-commercial",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'172.18.255.2'"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MESH_IP=!kubectl get svc seldon-mesh -n ns1 -o jsonpath='{.status.loadBalancer.ingress[0].ip}'\n",
    "MESH_IP_NS1=MESH_IP[0]\n",
    "import os\n",
    "os.environ['MESH_IP_NS1'] = MESH_IP_NS1\n",
    "MESH_IP_NS1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "012886cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'172.18.255.4'"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "MESH_IP=!kubectl get svc seldon-mesh -n ns2 -o jsonpath='{.status.loadBalancer.ingress[0].ip}'\n",
    "MESH_IP_NS2=MESH_IP[0]\n",
    "import os\n",
    "os.environ['MESH_IP_NS2'] = MESH_IP_NS2\n",
    "MESH_IP_NS2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "speaking-bracelet",
   "metadata": {},
   "source": [
    "### Run Models in Different Namespaces"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "operating-console",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "apiVersion: mlops.seldon.io/v1alpha1\r\n",
      "kind: Model\r\n",
      "metadata:\r\n",
      "  name: iris\r\n",
      "spec:\r\n",
      "  storageUri: \"gs://seldon-models/scv2/samples/mlserver_1.3.5/iris-sklearn\"\r\n",
      "  requirements:\r\n",
      "  - sklearn\r\n",
      "  memory: 100Ki\r\n"
     ]
    }
   ],
   "source": [
    "!cat ./models/sklearn-iris-gs.yaml"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "exempt-bumper",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io/iris created\r\n"
     ]
    }
   ],
   "source": [
    "!kubectl create -f ./models/sklearn-iris-gs.yaml -n ns1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "beneficial-logan",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io/iris condition met\r\n"
     ]
    }
   ],
   "source": [
    "!kubectl wait --for condition=ready --timeout=300s model --all -n ns1"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "67900afd",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "\t\"model_name\": \"iris_1\",\r\n",
      "\t\"model_version\": \"1\",\r\n",
      "\t\"id\": \"3ca1757c-df02-4e57-87c1-38311bcc5943\",\r\n",
      "\t\"parameters\": {},\r\n",
      "\t\"outputs\": [\r\n",
      "\t\t{\r\n",
      "\t\t\t\"name\": \"predict\",\r\n",
      "\t\t\t\"shape\": [\r\n",
      "\t\t\t\t1,\r\n",
      "\t\t\t\t1\r\n",
      "\t\t\t],\r\n",
      "\t\t\t\"datatype\": \"INT64\",\r\n",
      "\t\t\t\"parameters\": {\r\n",
      "\t\t\t\t\"content_type\": \"np\"\r\n",
      "\t\t\t},\r\n",
      "\t\t\t\"data\": [\r\n",
      "\t\t\t\t2\r\n",
      "\t\t\t]\r\n",
      "\t\t}\r\n",
      "\t]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon model infer iris --inference-host ${MESH_IP_NS1}:80 \\\n",
    "  '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}' "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "a1848c7d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"modelName\": \"iris_1\",\r\n",
      "  \"modelVersion\": \"1\",\r\n",
      "  \"outputs\": [\r\n",
      "    {\r\n",
      "      \"name\": \"predict\",\r\n",
      "      \"datatype\": \"INT64\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"1\"\r\n",
      "      ],\r\n",
      "      \"parameters\": {\r\n",
      "        \"content_type\": {\r\n",
      "          \"stringParam\": \"np\"\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"contents\": {\r\n",
      "        \"int64Contents\": [\r\n",
      "          \"2\"\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon model infer iris --inference-mode grpc --inference-host ${MESH_IP_NS1}:80 \\\n",
    "   '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' | jq -M ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "0843b13e",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io/iris created\r\n"
     ]
    }
   ],
   "source": [
    "!kubectl create -f ./models/sklearn-iris-gs.yaml -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "99e270be",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io/iris condition met\r\n"
     ]
    }
   ],
   "source": [
    "!kubectl wait --for condition=ready --timeout=300s model --all -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "ae262b3d",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "\t\"model_name\": \"iris_1\",\r\n",
      "\t\"model_version\": \"1\",\r\n",
      "\t\"id\": \"f706a23e-775f-4765-bd18-2e98d83bf7d5\",\r\n",
      "\t\"parameters\": {},\r\n",
      "\t\"outputs\": [\r\n",
      "\t\t{\r\n",
      "\t\t\t\"name\": \"predict\",\r\n",
      "\t\t\t\"shape\": [\r\n",
      "\t\t\t\t1,\r\n",
      "\t\t\t\t1\r\n",
      "\t\t\t],\r\n",
      "\t\t\t\"datatype\": \"INT64\",\r\n",
      "\t\t\t\"parameters\": {\r\n",
      "\t\t\t\t\"content_type\": \"np\"\r\n",
      "\t\t\t},\r\n",
      "\t\t\t\"data\": [\r\n",
      "\t\t\t\t2\r\n",
      "\t\t\t]\r\n",
      "\t\t}\r\n",
      "\t]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon model infer iris --inference-host ${MESH_IP_NS2}:80 \\\n",
    "  '{\"inputs\": [{\"name\": \"predict\", \"shape\": [1, 4], \"datatype\": \"FP32\", \"data\": [[1, 2, 3, 4]]}]}' "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "30b3342f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"modelName\": \"iris_1\",\r\n",
      "  \"modelVersion\": \"1\",\r\n",
      "  \"outputs\": [\r\n",
      "    {\r\n",
      "      \"name\": \"predict\",\r\n",
      "      \"datatype\": \"INT64\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"1\"\r\n",
      "      ],\r\n",
      "      \"parameters\": {\r\n",
      "        \"content_type\": {\r\n",
      "          \"stringParam\": \"np\"\r\n",
      "        }\r\n",
      "      },\r\n",
      "      \"contents\": {\r\n",
      "        \"int64Contents\": [\r\n",
      "          \"2\"\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon model infer iris --inference-mode grpc --inference-host ${MESH_IP_NS2}:80 \\\n",
    "   '{\"model_name\":\"iris\",\"inputs\":[{\"name\":\"input\",\"contents\":{\"fp32_contents\":[1,2,3,4]},\"datatype\":\"FP32\",\"shape\":[1,4]}]}' | jq -M ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "precious-development",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io \"iris\" deleted\n",
      "model.mlops.seldon.io \"iris\" deleted\n"
     ]
    }
   ],
   "source": [
    "!kubectl delete -f ./models/sklearn-iris-gs.yaml -n ns1\n",
    "!kubectl delete -f ./models/sklearn-iris-gs.yaml -n ns2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0b091f23",
   "metadata": {},
   "source": [
    "## Pipelines"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "21705cff",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io/tfsimple1 created\n",
      "model.mlops.seldon.io/tfsimple2 created\n",
      "model.mlops.seldon.io/tfsimple1 created\n",
      "model.mlops.seldon.io/tfsimple2 created\n"
     ]
    }
   ],
   "source": [
    "!kubectl create -f ./models/tfsimple1.yaml -n ns1\n",
    "!kubectl create -f ./models/tfsimple2.yaml -n ns1\n",
    "!kubectl create -f ./models/tfsimple1.yaml -n ns2\n",
    "!kubectl create -f ./models/tfsimple2.yaml -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "277f1ff7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io/tfsimple1 condition met\n",
      "model.mlops.seldon.io/tfsimple2 condition met\n",
      "model.mlops.seldon.io/tfsimple1 condition met\n",
      "model.mlops.seldon.io/tfsimple2 condition met\n"
     ]
    }
   ],
   "source": [
    "!kubectl wait --for condition=ready --timeout=300s model --all -n ns1\n",
    "!kubectl wait --for condition=ready --timeout=300s model --all -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "733b3f95",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pipeline.mlops.seldon.io/tfsimples created\n",
      "pipeline.mlops.seldon.io/tfsimples created\n"
     ]
    }
   ],
   "source": [
    "!kubectl create -f ./pipelines/tfsimples.yaml -n ns1\n",
    "!kubectl create -f ./pipelines/tfsimples.yaml -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "16dcb6e3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pipeline.mlops.seldon.io/tfsimples condition met\n",
      "pipeline.mlops.seldon.io/tfsimples condition met\n"
     ]
    }
   ],
   "source": [
    "!kubectl wait --for condition=ready --timeout=300s pipeline --all -n ns1\n",
    "!kubectl wait --for condition=ready --timeout=300s pipeline --all -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "7b2f86fc",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"outputs\": [\r\n",
      "    {\r\n",
      "      \"name\": \"OUTPUT0\",\r\n",
      "      \"datatype\": \"INT32\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"16\"\r\n",
      "      ],\r\n",
      "      \"contents\": {\r\n",
      "        \"intContents\": [\r\n",
      "          2,\r\n",
      "          4,\r\n",
      "          6,\r\n",
      "          8,\r\n",
      "          10,\r\n",
      "          12,\r\n",
      "          14,\r\n",
      "          16,\r\n",
      "          18,\r\n",
      "          20,\r\n",
      "          22,\r\n",
      "          24,\r\n",
      "          26,\r\n",
      "          28,\r\n",
      "          30,\r\n",
      "          32\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    },\r\n",
      "    {\r\n",
      "      \"name\": \"OUTPUT1\",\r\n",
      "      \"datatype\": \"INT32\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"16\"\r\n",
      "      ],\r\n",
      "      \"contents\": {\r\n",
      "        \"intContents\": [\r\n",
      "          2,\r\n",
      "          4,\r\n",
      "          6,\r\n",
      "          8,\r\n",
      "          10,\r\n",
      "          12,\r\n",
      "          14,\r\n",
      "          16,\r\n",
      "          18,\r\n",
      "          20,\r\n",
      "          22,\r\n",
      "          24,\r\n",
      "          26,\r\n",
      "          28,\r\n",
      "          30,\r\n",
      "          32\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline infer tfsimples --inference-mode grpc --inference-host ${MESH_IP_NS1}:80 \\\n",
    "    '{\"model_name\":\"simple\",\"inputs\":[{\"name\":\"INPUT0\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,16]},{\"name\":\"INPUT1\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,16]}]}' | jq -M ."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "9529a039",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\r\n",
      "  \"outputs\": [\r\n",
      "    {\r\n",
      "      \"name\": \"OUTPUT0\",\r\n",
      "      \"datatype\": \"INT32\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"16\"\r\n",
      "      ],\r\n",
      "      \"contents\": {\r\n",
      "        \"intContents\": [\r\n",
      "          2,\r\n",
      "          4,\r\n",
      "          6,\r\n",
      "          8,\r\n",
      "          10,\r\n",
      "          12,\r\n",
      "          14,\r\n",
      "          16,\r\n",
      "          18,\r\n",
      "          20,\r\n",
      "          22,\r\n",
      "          24,\r\n",
      "          26,\r\n",
      "          28,\r\n",
      "          30,\r\n",
      "          32\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    },\r\n",
      "    {\r\n",
      "      \"name\": \"OUTPUT1\",\r\n",
      "      \"datatype\": \"INT32\",\r\n",
      "      \"shape\": [\r\n",
      "        \"1\",\r\n",
      "        \"16\"\r\n",
      "      ],\r\n",
      "      \"contents\": {\r\n",
      "        \"intContents\": [\r\n",
      "          2,\r\n",
      "          4,\r\n",
      "          6,\r\n",
      "          8,\r\n",
      "          10,\r\n",
      "          12,\r\n",
      "          14,\r\n",
      "          16,\r\n",
      "          18,\r\n",
      "          20,\r\n",
      "          22,\r\n",
      "          24,\r\n",
      "          26,\r\n",
      "          28,\r\n",
      "          30,\r\n",
      "          32\r\n",
      "        ]\r\n",
      "      }\r\n",
      "    }\r\n",
      "  ]\r\n",
      "}\r\n"
     ]
    }
   ],
   "source": [
    "!seldon pipeline infer tfsimples --inference-mode grpc --inference-host ${MESH_IP_NS2}:80 \\\n",
    "    '{\"model_name\":\"simple\",\"inputs\":[{\"name\":\"INPUT0\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,16]},{\"name\":\"INPUT1\",\"contents\":{\"int_contents\":[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16]},\"datatype\":\"INT32\",\"shape\":[1,16]}]}' | jq -M ."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a3fe4c34",
   "metadata": {},
   "source": [
    "If you have installed Kafka via the ansible playbook setup-ecosystem then you can use the following command to see the consumer group ids which are reflecting the settings we created."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "6a1eb5f7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "myorg-ns2-seldon-pipelinegateway-dfd61b49-4bb9-4684-adce-0b7cc215d3af\r\n",
      "myorg-ns2-seldon-modelgateway-17\r\n",
      "myorg-ns1-seldon-pipelinegateway-d4fc83e6-29cb-442e-90cd-92a389961cfe\r\n",
      "myorg-ns2-seldon-modelgateway-60\r\n",
      "myorg-ns2-seldon-dataflow-73d465744b7b1b5be20e88d6245e50bd\r\n",
      "myorg-ns1-seldon-modelgateway-60\r\n",
      "myorg-ns1-seldon-modelgateway-17\r\n",
      "myorg-ns1-seldon-dataflow-f563e04e093caa20c03e6eced084331b\r\n"
     ]
    }
   ],
   "source": [
    "!kubectl exec seldon-kafka-0 -n seldon-mesh -- bin/kafka-consumer-groups.sh --list --bootstrap-server localhost:9092"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a360fcb",
   "metadata": {},
   "source": [
    "We can similarly show the topics that have been created."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "id": "71285ba0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "__consumer_offsets\r\n",
      "myorg.ns1.errors.errors\r\n",
      "myorg.ns1.model.iris.inputs\r\n",
      "myorg.ns1.model.iris.outputs\r\n",
      "myorg.ns1.model.tfsimple1.inputs\r\n",
      "myorg.ns1.model.tfsimple1.outputs\r\n",
      "myorg.ns1.model.tfsimple2.inputs\r\n",
      "myorg.ns1.model.tfsimple2.outputs\r\n",
      "myorg.ns1.pipeline.tfsimples.inputs\r\n",
      "myorg.ns1.pipeline.tfsimples.outputs\r\n",
      "myorg.ns2.errors.errors\r\n",
      "myorg.ns2.model.iris.inputs\r\n",
      "myorg.ns2.model.iris.outputs\r\n",
      "myorg.ns2.model.tfsimple1.inputs\r\n",
      "myorg.ns2.model.tfsimple1.outputs\r\n",
      "myorg.ns2.model.tfsimple2.inputs\r\n",
      "myorg.ns2.model.tfsimple2.outputs\r\n",
      "myorg.ns2.pipeline.tfsimples.inputs\r\n",
      "myorg.ns2.pipeline.tfsimples.outputs\r\n"
     ]
    }
   ],
   "source": [
    "!kubectl exec seldon-kafka-0 -n seldon-mesh -- bin/kafka-topics.sh --bootstrap-server=localhost:9092 --list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "b0b4b82f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "pipeline.mlops.seldon.io \"tfsimples\" deleted\n",
      "pipeline.mlops.seldon.io \"tfsimples\" deleted\n"
     ]
    }
   ],
   "source": [
    "!kubectl delete -f ./pipelines/tfsimples.yaml -n ns1\n",
    "!kubectl delete -f ./pipelines/tfsimples.yaml -n ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "941ed2c3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "model.mlops.seldon.io \"tfsimple1\" deleted\n",
      "model.mlops.seldon.io \"tfsimple2\" deleted\n",
      "model.mlops.seldon.io \"tfsimple1\" deleted\n",
      "model.mlops.seldon.io \"tfsimple2\" deleted\n"
     ]
    }
   ],
   "source": [
    "!kubectl delete -f ./models/tfsimple1.yaml -n ns1\n",
    "!kubectl delete -f ./models/tfsimple2.yaml -n ns1\n",
    "!kubectl delete -f ./models/tfsimple1.yaml -n ns2\n",
    "!kubectl delete -f ./models/tfsimple2.yaml -n ns2"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "280c1dcd",
   "metadata": {},
   "source": [
    "## TearDown"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "e694edee",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "release \"seldon-v2-servers\" uninstalled\n",
      "release \"seldon-v2-servers\" uninstalled\n"
     ]
    }
   ],
   "source": [
    "!helm delete seldon-v2-servers -n ns1 --wait\n",
    "!helm delete seldon-v2-servers -n ns2 --wait"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "8b00bd3e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "release \"seldon-v2-runtime\" uninstalled\n",
      "release \"seldon-v2-runtime\" uninstalled\n"
     ]
    }
   ],
   "source": [
    "!helm delete seldon-v2-runtime -n ns1 --wait\n",
    "!helm delete seldon-v2-runtime -n ns2 --wait"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "4c671429",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "release \"seldon-v2\" uninstalled\r\n"
     ]
    }
   ],
   "source": [
    "!helm delete seldon-v2 -n seldon-mesh --wait"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "72b24840",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "release \"seldon-core-v2-crds\" uninstalled\r\n"
     ]
    }
   ],
   "source": [
    "!helm delete seldon-core-v2-crds -n seldon-mesh"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "e7773481",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "namespace \"ns1\" deleted\n",
      "namespace \"ns2\" deleted\n"
     ]
    }
   ],
   "source": [
    "!kubectl delete namespace ns1\n",
    "!kubectl delete namespace ns2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "bf5ce6cd",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
